<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  components: {},
  data() {
    return {
      appWindow: window,
      form: {
        // 支持的银行列表
        bank: ["xx银行", "sfas"],
        // 自动打款
        auto_remit: 1,
        // 提现金额-申请提现金额小于该设置时，自动审核通过
        commission_check_money: null,
        // 分佣总额不得超过商品利润
        commission_less_profit: 1,
        // 分销商等级-该等级以上分销商提现时，自动审核通过
        commission_level: null,
        // 佣金计算方式
        commission_type: 1,
        // 扣除商品成本
        deduct_cost: 1,
        // 手动提现
        manual: 1,
        // 结算天数
        settlement_days: null,
        // 提现到支付宝
        withdraw_alipay: 1,
        // 提现到商城余额
        withdraw_balance: 1,
        // 提现到银行
        withdraw_bank: 1,

        // 免手续费区间开始
        withdraw_begin: null,
        // 免手续费区间结束
        withdraw_end: null,
        // 佣金提现手续费
        withdraw_charge: null,
        // 提现审核
        withdraw_check: 1,
        
        // 最低提现额度
        withdraw_limit: null,
        // 提现到微信钱包
        withdraw_wechat: 1,



        // 1：商品折扣价 or 2：实际支付
        settle_module: 1,
        // 结算周期（天）
        settle_cycle: "",
        
      },

      levelList: [],

      load: true,
    };
  },
  methods: {
    // 验证 
    validate() {
      return new Promise((resolve, reject) => {
          this.$refs["editForm"].validate((valid) => {
              valid ? resolve(true) : resolve(false)
          });
      });
    },
    // 获取等级
    async getLevel() {
      let res = await this.$vFN.Http.post({
        url: "plugin/distribution/backend/levels/index?pageNum=1&pageSize=20",
      }, window);
      this.levelList = res.data.list;
    },
    add() {
      this.form.bank.push("");
    },
    del(item, index) {
      if(this.form.bank.length == 1) {
        return;
      }else {
        this.$delete(this.form.bank, index);
      }
    },
    async getData() {
      let res = await this.$vFN.Http.post({
        url: "plugin/distribution/backend/settings/settlement/get",
      }, window);
      this.form = res.data;
      this.load = false;
    },
    async sum() {
      if (!await this.validate()) {
        return
      }
      this.load = true;
      let res = await this.$vFN.Http.post({
        url: "plugin/distribution/backend/settings/settlement/set",
        data: this.form,
      }, window)
      if(res.code == 200) {
        this.$vFN.Tools.messageSuccess("操作成功");
        this.getData();
      }
    },
    // 初始化
    async init() {
      this.getData();
      this.getLevel()
    },
  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>